import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import resolve from 'rollup-plugin-node-resolve';
import * as path from 'path';

let ip: string;
const env = process.env.RUNTIME_ENV;

switch (env) {
  case 'dev':
    ip = 'http://82.156.217.14:8000';
    break;
  case 'loca':
    ip = 'http://localhost:8000';
    break;
  default:
    ip = 'http://82.156.217.14:8000';
}

console.log('ip', ip);

export default defineConfig({
  plugins: [vue()],
  server: {
    host: '0.0.0.0',
    port: 3000,
    proxy: {
      '/api': {
        target: ip,
        changeOrigin: true,
      },
    },
  },

  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@ajax': path.resolve(__dirname, 'src/unit/api/ajax'),
    },
  },

  css: {
    preprocessorOptions: {
      less: {
        // modifyVars: lessVarsConfig,
        javascriptEnabled: true,
      },
    },
  },

  build: {
    rollupOptions: {
      plugins: [resolve()],
      input: {
        main: path.resolve(__dirname, 'index.html'),
        ar: path.resolve(__dirname, 'ar.html'),
      },
    },
  },
});
